//
//  MYReplenishmentListViewController.m
//  MiYuan_iOS
//
//  Created by zhangyongbing on 2018/4/18.
//  Copyright © 2018年 zhangyongbing. All rights reserved.
//

#import "MYReplenishmentListViewController.h"
#import "MY_ReplenushmentListAPI.h"
#import "MYReplenishmentListTableCell.h"

@interface MYReplenishmentListViewController ()
@property (nonatomic,weak) IBOutlet   UITableView     *tabMain;
@property (nonatomic,strong) NSMutableArray     *arrayData;
@property (nonatomic,weak) IBOutlet   UIActivityIndicatorView *active;
@property (nonatomic,weak) IBOutlet   UIView          *viewHead;

@end

@implementation MYReplenishmentListViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self getReplenishmentListDataFromServices];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSString *version= [UIDevice currentDevice].systemVersion;
    
    if(version.doubleValue >=11.0) {
        
    }else{
        // 针对 11.0 以下的iOS系统进行处理
        for (NSLayoutConstraint *constraint in self.viewHead.superview.constraints) {
            if (constraint.firstItem == self.viewHead && constraint.firstAttribute == NSLayoutAttributeTop) {
                constraint.constant = 20;
            }
        }
        
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)getReplenishmentListDataFromServices
{
    [self.active startAnimating];
    [MY_ReplenushmentListAPI myGetReplenushmentListWithcomplationHandler:^(OCJBaseResponceModel *responseModel) {
        [self.active stopAnimating];
        NSArray *array = [responseModel.ocjDic_data objectForKey:@"array"];
        [self.arrayData removeAllObjects];
        [self.arrayData addObjectsFromArray:array];
        [self.tabMain reloadData];
    }];
}

#pragma mark - tableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arrayData.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    CGFloat height = 80;
    return height;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = [self.arrayData objectAtIndex:indexPath.row];
    static NSString * cellIdentifiernoe = @"MYReplenishmentListTableCell";
    MYReplenishmentListTableCell *cell  = (MYReplenishmentListTableCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifiernoe];
    
    if (!cell)
    {
        [tableView registerNib:[UINib nibWithNibName:@"MYReplenishmentListTableCell" bundle:nil] forCellReuseIdentifier:cellIdentifiernoe];
        cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifiernoe];
    }
    [cell setDataToViewWithDictionary:dic];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    NSDictionary *dic = [self.arrayData objectAtIndex:indexPath.row];
//    NSString *strid = [NSString stringWithFormat:@"%@",[dic objectForKey:@"id"]];
//    NSString *controlNumber = [NSString stringWithFormat:@"%@",[dic objectForKey:@"controlNumber"]];
//    MYMachineGoodListViewController *ctrl = [[MYMachineGoodListViewController alloc] initWithMachineId:strid ControlNumber:controlNumber];
//    [[PublicDefine shareInstance].navigation pushViewController:ctrl animated:YES];
    
}

- (NSMutableArray *)arrayData
{
    if (_arrayData == nil) {
        _arrayData = [[NSMutableArray alloc] init];
    }
    return _arrayData;
}

@end
